package com.nidu.demo.permission.command;

import com.alibaba.cola.dto.Response;
import com.nidu.demo.role.dto.RoleMenuAssignCmd;
import com.nidu.demo.role.gateway.RoleMenuGateway;
import com.nidu.demo.user.dto.*;
import com.nidu.demo.user.gateway.UserRoleGateway;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class PermissionUpdateCmdExe {

    private final UserRoleGateway userRoleGateway;

    private final RoleMenuGateway roleMenuGateway;

    public Response assignUserRole(UserRoleAssignCmd cmd) {
        userRoleGateway.rebindUserRoles(cmd.getUserId(), cmd.getRoleIds());
        return Response.buildSuccess();
    }

    public Response assignRoleMenu(RoleMenuAssignCmd cmd) {
        roleMenuGateway.rebindRoleMenus(cmd.getRoleId(), cmd.getMenuIds());
        return Response.buildSuccess();
    }
}
